<?php
/*
 * @Author: your name
 * @Date: 2020-12-24 09:25:29
 * @LastEditTime: 2020-12-24 11:31:13
 * @LastEditors: Please set LastEditors
 * @Description: 授权模块
 * @FilePath: /special/application/adminapiv3/model/ServerAuthModuleModel.php
 */
namespace app\adminapiv3\model;


class ServerAuthModuleModel extends BaseModel
{
    //客户端模块标识
    const CLIENT_MODULE_KEY = 'client';

    /**
     * 查询所有的模块授权信息
     * @param string $field 查询字段
    */
    public function getAllAuthModule($field = '*'){
       return $this->field($field)->select()->toArray();
    }

    /**
     * 查询某个资产组的client模块的授权数量界限值
     * @param int $groupId
     */
    public function getClientModuleLimit($groupId, $moduleKey = null){
         $moduleKey = $moduleKey ? $moduleKey : self::CLIENT_MODULE_KEY;
         return $this->alias('m')
            ->leftJoin('server_host_group_module g','m.id=g.module_id')
            ->where([
                'm.module_key' => $moduleKey, //默认客户端模块
                'g.group_id' => $groupId, //该资产组id
            ])->value('g.number');
    }

    /**
     * 查询整个client模块的授权数量界限值
    */
    public function getClientModuleMostLimit($moduleKey = null){
        $moduleKey = $moduleKey ? $moduleKey : self::CLIENT_MODULE_KEY;
        return $this->where([
            'module_key' => $moduleKey, //客户端模块
        ])->value('number');
    }

    /**
     * 查询某个资产组的client模块的结束时间界限值
     * @param int $groupId 资产组id
     */
    public function getClientModuleEtime($groupId,$moduleKey = null){
        $moduleKey = $moduleKey ? $moduleKey : self::CLIENT_MODULE_KEY;
        return $this->alias('m')
            ->leftJoin('server_host_group_module g','m.id=g.module_id')
            ->where([
                'm.module_key' => $moduleKey, //默认客户端模块
                'g.group_id' => $groupId, //该资产组id
            ])->value('g.etime');
    }

    /**
     * 查询整个client模块的结束时间界限值
    */
    public function getClientModuleMostEtime($moduleKey = null){
        $moduleKey = $moduleKey ? $moduleKey : self::CLIENT_MODULE_KEY;
        return $this->where([
            'module_key' => $moduleKey, //客户端模块
        ])->value('etime');
    }

}